import { Controller, Get, Query, Headers, Post, Body, Patch, Param, Delete, HttpException, HttpStatus, UseFilters, ParseIntPipe, UseGuards } from "@nestjs/common";
import { ApiBasicAuth, ApiBody, ApiParam, ApiQuery, ApiTags } from "@nestjs/swagger";
import { DataEntity } from "src/Entity/data.entity";
import { JwtAuthGuard } from "src/modules/auth/guard/jwt-auth.guard";
import { Like } from "typeorm";
import { GetApiMessage } from "../descriptor/action.descriptor";
import { MyApi } from "../descriptor/function.descriptoor";
import { MyController } from "../descriptor/http.decorator";
import { ActionService } from "./action.service";



@Controller('action')
// @GetClassName()
@MyController('gg')
export class ActionController {
    constructor(
        private readonly actionService: ActionService,

    ) { }

    // @Get()
    // @ApiQuery({ name: 'id' })
    // fetch(@Query() { id }, @Headers('token') token): string {
    //     if (!id) {
    //         throw new HttpException(
    //             { status: HttpStatus.BAD_REQUEST, message: '请求id,必填', error: 'id is require' },
    //             HttpStatus.BAD_REQUEST,
    //         );
    //     }
    //     return this.helloService.fetch(id);
    // }

    // @Post()
    // @ApiBody({ description: '填写内容' })
    // save(@Body() { message }): string {
    //     return this.helloService.save(message);
    // }

    // @Patch(':id')
    // @ApiParam({ name: 'id' })
    // @ApiBody({ description: '填写内容' })
    // // @GetApiMessage("weiqi")
    // update(@Param('id', ParseIntPipe) id: number, @Body() { message }): string {
    //     return this.helloService.update(id, message);
    // }

    @Get()
    async findAll() {
        return await this.actionService.findAll();
    }

    @Delete(':id')
    async deleteById(@Param() { id }) {
        return await DataEntity.delete(id);
    }
    @Post('data')
    async getData(@Body() { body }) {
        console.log(body);
        return await this.actionService.getData(body)
    }

    @Get('name')
    async findByName(@Query() { value }) {
        if (value == null) {
            return await this.actionService.findAll();
        } else {
            // console.log(value);
            return await DataEntity.find({ where: { name: Like(`%${value}%`) } })
        }

    }

    @Get()
    // @GetApiMessage('获取api')
    @MyApi('获取信息')
    getMessage() {
        // console.log(globafn.china);
        return this.actionService.getMessage();
    }

}